<?php

class Story_Widget_CreateArticleController extends
Engine_Content_Widget_Abstract
{

	public function indexAction()
	{		 
		$story = null;		
		$this->view->form = $form = new Story_Form_Create_Custom(array(
				'category' => Story_Model_Category::ARTICLE,
				'tit' => 'Article',
		));
		if( Engine_Api::_()->core()->hasSubject() ) {
			$story = Engine_Api::_()->core()->getSubject();
			
			if(!$story->canView(Story_Model_Category::ARTICLE)){
    			return $this->setNoRender();
    		}
			
			//Populate data
			$this->view->story_id = $story->getIdentity();			
			$form->populate($story->toArray());
			
			$body = "body_" . $story->category_id;
			$form->$body->setValue($story->body);
		}
		$viewer = Engine_Api::_()->user()->getViewer();
		$this->view->can_create = Engine_Api::_()->authorization()->isAllowed('story', $viewer, 'create');

		if (!$this->view->can_create) {
			return $this->setNoRender();
		}

		
	}

}
